# -*- coding: utf-8 -*-
# @File : playwrightStudy_定位方法2.py
# @Time : 2024/5/16 16:29
# @Author : syq
# @Email : 1721169065@qq.com
# @Software: PyCharm
'''
知识点：playwright提供的定位方式
1.id属性
2.text文本
3.css
4.xpath

'''
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
    browser=p.chromium.launch(headless=False)
    page=browser.new_page()
    page.goto(r'F:\pycharmGit\playwrightStudy\demo.html')
    #1.id属性
    # page.locator('id="username"').fill('admin') #这是错误写法，不要加引号
    # page.locator('id=username').fill('admin')
    #2.text 文本
    # page.locator('text=百度一下，你就知道').click()
    #3.css
    #参考网址：https://www.w3school.com.cn/cssref/css_selectors.asp
    # page.locator('#username').fill('admin')
    #4.xpath
    #参考网址：https://www.w3school.com.cn/xpath/xpath_axes.asp
    page.locator('xpath=//*[@id="username"]').fill('admin')

    page.wait_for_timeout(5000)
